#!/bin/sh
# Compile:by-lanse    2018-08-28

echo -e "\e[1;36m 下载 '网络收集' HOSTS 规则 \e[0m\n"
TMP_ABD=/tmp/tmp_abd
TMP_ABD2=/tmp/tmp_abd2
TMP_ABD3=/tmp/tmp_abd3
TMP_ABD4=/tmp/tmp_abd4
ABD=/tmp/abd

[ -f ${ABD} ] && rm -rf ${ABD};[ -f ${TMP_ABD2} ] && rm -rf ${TMP_ABD2};[ -f ${TMP_ABD3} ] && rm -rf ${TMP_ABD3};[ -f ${TMP_ABD4} ] && rm -rf ${TMP_ABD4}
for URL in \
	"https://easylist-downloads.adblockplus.org/easylistchina.txt"
do
	wget -t 15 -T 50 -c --no-check-certificate -O- "${URL}" \
	| grep ^\|\|[^\*]*\^$ | sed -e "s:||:0.0.0.0 :"  -e "s/.$//" >> ${TMP_ABD4}
done

wget --no-check-certificate -t 20 -T 60 -O- https://cdn.jsdelivr.net/gh/vokins/yhosts@master/dnsmasq/union.conf \
| awk '{if($0!=line)print; line=$0}' | sed -E -e "s/address=\/./0.0.0.0\ /" -e "s/0.0.0.0$//" -e "/#/d" -e "s/.$//" >> ${TMP_ABD2}
[ $? -eq 0 ] || sh /tmp/abd.conf

wget --no-check-certificate -t 20 -T 60 -O- https://cdn.jsdelivr.net/gh/xinggsf/Adblock-Plus-Rule@master/ABP-FX.txt \
| grep ^\|\|[^\*]*\^$ | sed -e "s:||:0.0.0.0 :"  -e "s/.$//" >> ${TMP_ABD3}

sleep 2
cat ${TMP_ABD2} ${TMP_ABD3} ${TMP_ABD4} > ${ABD}
#sort -n ${TMP_ABD} |uniq >> ${ABD}

echo -e "\033[45;37m 分享 'hosts' 规则下载完成 \033[0m\n"
# 删除临时缓存
rm -rf ${TMP_ABD2} ${TMP_ABD3} ${TMP_ABD4} 2> /dev/null
#rm ${TMP_ABD} 2> /dev/null
